package com.yulan.Tree;

/**
 * 543. 二叉树的直径
 */
public class LeetCode_543 {

    int ans = 1;
    public int diameterOfBinaryTree(TreeNode root) {
        ans = 1;
        dfs(root);
        return ans-1;
    }

    public int dfs(TreeNode root ){
        if(root == null)
            return 0;
        int l = dfs(root.left);
        int r = dfs(root.right);
        ans = Math.max(ans,l+r+1);
        return Math.max(l,r)+1;
    }
}
